From 90bcf5c82c6b2ed595d0d6bfcbe34ab15c1930d2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Mar 2017 10:40:12 +0300 Subject: [PATCH] Fix crate_types in serialized targets --- src/cargo/core/manifest.rs | 23 +++++------------------ tests/metadata.rs | 2 +- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 24cfd4d42..ad9a129af 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -112,23 +112,6 @@ pub enum TargetKind { CustomBuild, } -impl TargetKind { - /// Returns a vector of crate types as specified in a manifest - pub fn crate_types(&self) -> Vec<&str> { - use self::TargetKind::*; - match *self { - Lib(ref kinds) | ExampleLib(ref kinds) => { - kinds.iter().map(LibKind::crate_type).collect() - } - Bin => vec!["bin"], - ExampleBin => vec!["example"], - Test => vec!["test"], - CustomBuild => vec!["custom-build"], - Bench => vec!["bench"] - } - } -} - impl ser::Serialize for TargetKind { fn serialize(&self, s: S) -> Result where S: ser::Serializer, @@ -207,7 +190,11 @@ pub struct Target { #[derive(Serialize)] struct SerializedTarget<'a> { + /// Is this a `--bin bin`, `--lib`, `--example ex`? + /// Serialized as a list of strings for historical reasons. kind: &'a TargetKind, + /// Corresponds to `--crate-type` compiler attribute. + /// See https://doc.rust-lang.org/reference.html#linkage crate_types: Vec<&'a str>, name: &'a str, src_path: &'a PathBuf, @@ -217,7 +204,7 @@ impl ser::Serialize for Target { fn serialize(&self, s: S) -> Result { SerializedTarget { kind: &self.kind, - crate_types: self.kind.crate_types(), + crate_types: self.rustc_crate_types(), name: &self.name, src_path: &self.src_path, }.serialize(s) diff --git a/tests/metadata.rs b/tests/metadata.rs index 313326391..04216a39d 100644 --- a/tests/metadata.rs +++ b/tests/metadata.rs @@ -308,7 +308,7 @@ name = "ex" }, { "kind": [ "example" ], - "crate_types": [ "example" ], + "crate_types": [ "bin" ], "name": "ex", "src_path": "[..][/]foo[/]examples[/]ex.rs" } -- 2.30.2